setCookie("timezone", new Date().getTimezoneOffset()/60);

function setCookie(name, value, expires, path, domain, secure) 
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function _form_su_validateAll() {
    var i = 1;
    for (i = 1; i <= 6; i++ ) {
        if (_form_su_validate(i, 2) != 0) {            
            return false;            
        }
    }    
    
    hideHintBox();
    document.getElementById('_form_su1').style.display = "none";
    document.getElementById('_form_su2').style.display = "block";
}

function hideCaptcha() {
    document.getElementById('_form_su1').style.display = "block";
    document.getElementById('_form_su2').style.display = "none";
}

function _form_su_validate(nr, caller) {
    var rs = 0;
    var type = "ok";
    
    switch(nr) {
        case 1: rs = _form_su_checkEmail();  break;
        case 2: rs = _form_su_checkPassword();  break;
        case 3: rs = _form_su_checkName(); break;
        case 4: rs = _form_su_checkGender(); break;
        case 5: rs = _form_su_checkBirthday(); break;
        case 6: rs = _form_su_checkCountry(); break;
        default: break;                
    }   
        
    if (rs == 1) type = "hint";
    if (rs == 2) type = "error";
    
    if (rs == 0) {
        showHintBox('', "ok", nr);    
        return rs;
    }
        
    if ( (caller == 1 && nr <= 3) ) {
        if (type == "hint")
            showHintBox(hints[nr - 1], "error", nr);    
        else
        if (type == "error")
            showHintBox(error[nr - 1], type, nr);    
    }
    else
    if (caller == 2) {        
        if (rs == 1 && nr <= 3) 
            showHintBox(hints[nr - 1], "error", nr);    
        else       
        if (rs == 2) 
            showHintBox(error[nr - 1], "error", nr);    
    }
    
    return rs; 
}

function _form_su_checkGender() {
    return 0;
}

function _form_su_checkBirthday() {
    var y = document.getElementById('_form_su_year');
    var m = document.getElementById('_form_su_month');
    var d = document.getElementById('_form_su_day');
    
    
    if (y.value == 0 || m.value == 0 || d.value == 0) {
        return 2;
    }
    return 0;
}

function _form_su_checkCountry() {
    var e = document.getElementById('_form_su_country');
    if (e.value == 0) {
        return 2;
    }
    return 0;
}

function _form_su_checkName() {
    var e = document.getElementById('_form_su_fullname');
    if (e.value == "") {
        return 1;
    }
    else  {
        return 0;
    }
}

function _form_su_checkPassword() {
    var e = document.getElementById('_form_su_password');
    if (e.value == "") {
        return 1;
    }
    else if (e.value.length < 6 || e.value.length > 15) {
        return 2;
    }
    return 0;
}

function _form_su_checkEmail() {
    var re = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/
    var e = document.getElementById('_form_su_email');
    if (e.value == "") {
        return 1;
    }
    else  {
        if (e.value.search(re) ==  - 1) {
            return 2;
        }
        else  {
            return 0;
        }
    }
}

function hideHintBox() {
    var err = document.getElementById('_form_su_err1');
    err.style.visibility = "hidden";
    err.style.display = "none";
}

function showHintBox(msg, type, el) {
    var err = document.getElementById('_form_su_err1');

    if (type == 'ok') {
        err.style.display = "none";
        err.style.visibility = "hidden";
    }
    else  {
        err.style.display = "block";
        err.style.visibility = "visible";

        if (type == 'hint') {
            err.className = "hint";
        }
        if (type == 'error') {
            err.className = "error";
        }

        if (el == 1) {
            err.style.top = "220px";
        }
        else if (el == 2) {
            err.style.top = "243px";
        }
        else if (el == 3) {
            err.style.top = "266px";
        }
        else if (el == 4) {
            err.style.top = "289px";
        }
        else if (el == 5) {
            err.style.top = "315px";
        }
        else if (el == 6) {
            err.style.top = "338px";
        }

        var _msg = document.getElementById('_form_su_he_msg');
        _msg.innerHTML = msg;
    }

}
